package com.banshuibao.bsb_android.util;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.activity.PayActivity;

/**
 * Created by Administrator on 2017/12/26.
 */

public class DialogUtils {

    public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setMessage(Html.fromHtml(message));
        builder.setPositiveButton("确定", onClickListener);
        builder.setNegativeButton("取消", null);
        return builder;
    }

    private static AlertDialog.Builder getDialog(Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        return builder;
    }

    public static Dialog payDialog(final Activity activity, String message, final String uuid, final String price, final String title, final int flag) {
        final Dialog dialog = new Dialog(activity, R.style.Buy_dialog);
        View view = activity.getLayoutInflater().inflate(R.layout.dialog_buy, null, false);
        TextView title_text = view.findViewById(R.id.title);
        TextView buy1 = view.findViewById(R.id.buy1);
        TextView buy2 = view.findViewById(R.id.buy2);
        ImageView close = view.findViewById(R.id.close);
        title_text.setText(message);
        dialog.setContentView(view);
        View.OnClickListener l = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.buy1:
                        Intent intent = new Intent(activity, PayActivity.class);
                        intent.putExtra("flag", flag);
                        intent.putExtra("content", title);
                        intent.putExtra("price", price);
                        intent.putExtra("uuid", uuid);
                        activity.startActivityForResult(intent, 200);
                        if (dialog.isShowing())
                            dialog.dismiss();
                        break;
                    case R.id.buy2:
                        IntentManager.goToVipActivity(activity, "");
                        if (dialog.isShowing())
                            dialog.dismiss();
                        break;
                    case R.id.close:
                        if (dialog.isShowing())
                            dialog.dismiss();
                        break;
                }
            }
        };
        buy1.setOnClickListener(l);
        buy2.setOnClickListener(l);
        close.setOnClickListener(l);
        return dialog;
    }

}
